home *** CD-ROM | disk | FTP | other *** search
- Path: news.sni.de!news
- From: Josef Moellers <mollers.pad@sni.de>
- Newsgroups: comp.lang.c
- Subject: Re: strings
- Date: 29 Jan 1996 11:07:47 GMT
- Organization: Siemens Nixdorf Informationssysteme AG, Paderborn, Germany
- Message-ID: <4ei9q3$fh1@nervous.pdb.sni.de>
- References: <4eg9qj$1ut4@sp115.ocs.lsu.edu> <TANMOY.96Jan28104305@qcd.lanl.gov>
- NNTP-Posting-Host: uranium.pdb.sni.de
- X-Newsreader: NN version 6.5.0 #2
-
- In <TANMOY.96Jan28104305@qcd.lanl.gov> tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) writes:
-
- >In article <4eg9qj$1ut4@sp115.ocs.lsu.edu> eenaya@unix1.sncc.lsu.edu
- >(Pradeep Nayar) writes:
- ><snip>
- > I saw this piece of code in a book somewhere.
-
- >Throw away the book: immediately.
-
- > char *str ;
-
- > str = "hello world"[10] ;
-
- > what does the second line do?
-
- >Nothing meaningful. In fact, the compiler must tell you that this is
- >incorrect: otherwise put your compiler exactly in the same place where
- >your book deserves to go :-)
-
- You _could_ be a little more precise:
- Assuming this is C (of which I know something) and not C++ (of which I
- know next to nothing), the only problem I see with the two lines quoted
- above is the asterisk in the definition of "str". If you leave out the
- asterisk, it's the declaration of a character and the assignment of the
- letter 'd' to the character.
-
- According to K&R/2nd, "A strings has type "array of characters" ...".
- So, the second line just uses index 10 to this array and retrieves the
- 'd'!
-
- Sortlike constructs can be found when converting digits to their
- respective ASCII representations:
-
- dig = number % 16;
- cdig = "0123456789abcdef"[dig];
-
- Hope this helps.
-
- Keep on converting,
-
- Josef
- --
- Josef Moellers work: mollers.pad@sni.de
- home: josef@firefox.pb.owl.de
-